package com.example.task1.ui.AllService.volunteer;

import android.os.Bundle;
import android.text.Html;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.VolunteerNewsDetailsBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class VolunteerNewsDetailActivity extends BaseActivity {

    private TextView tvTitle;
    private TextView tvTime;
    private ImageView image;
    private TextView tvSummary;
    private TextView tvContent;
    private int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volunteer_news_detail);
        id = getIntent().getIntExtra("id", 0);
        initView();
        initData();
    }

    private void initData() {
        Call<ApiResp> call = Api.api().get(MyApplication.TOKEN, "/prod-api/api/volunteer-service/news/" + id);
        Api.send(call, VolunteerNewsDetailsBean.class, new CallBack<VolunteerNewsDetailsBean>() {
            @Override
            public void success(VolunteerNewsDetailsBean data) {
                VolunteerNewsDetailsBean.DataDTO rows = data.getData();
                tvTitle.setText(rows.getTitle());
                tvContent.setText(Html.fromHtml(rows.getContent()));
                tvSummary.setText(rows.getSummary());
                tvTime.setText(rows.getCreateTime());
                MyApplication.glide(image, rows.getImgUrl());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    @Override
    public String getMyTitle() {
        return "新闻详情";
    }

    private void initView() {
        tvTitle = findViewById(R.id.tv_title);
        tvTime = findViewById(R.id.tv_time);
        image = findViewById(R.id.image);
        tvSummary = findViewById(R.id.tv_summary);
        tvContent = findViewById(R.id.tv_content);
    }
}